<?php
/**
 * 违规记录相关，无法检测违规是否到期
 */
use Doraemon\tools\Log;
use Doraemon\service\LocalRank\PublicPraiseRank as sPublicPraiseRank;
use Doraemon\model\Designer\DesignerViolationRecord as mDesignerViolationRecord;
use Doraemon\service\DesignerInfoLib\OperateInfoService as sOperateInfo;

class AdmViolationAction extends ActionPlugin {

    public function main()
    {
        Log::info('设计师违规记录开始接收到事件信息', $this->messageBody);
        $message = $this->messageBody;
        $table = $this->messageBody['table'] ?? '';
        $uid = 0;
        if (strstr($table, mDesignerViolationRecord::_TABLE_NAME)) {
            $eventType = $this->messageBody['type'] ?? '';
            $uid = $this->messageBody['data']['designer_uid'] ?? 0;
            $punishList = $this->messageBody['data']['punish_list'] ?? 0;
            $punishTypeList = [];
            $punishList = json_decode($punishList, true);
            foreach ($punishList as $punishItem) {
                if ($punishItem['is_punish']) {
                    $punishTypeList[] = $punishItem['punish_type'];
                }
            }
            if ($eventType == 'insert') {
                // 下本地口碑榜
                sPublicPraiseRank::offlineRankForDesignerViolation($punishTypeList);
                // 更新设计师信息库表中的是否有违规记录字段「is_violation」
                sOperateInfo::updateIsViolationFiled($uid, true);
            }
            if ($eventType == 'update') {
                // 更新设计师信息库表中的是否有违规记录字段「is_violation」
                sOperateInfo::updateIsViolationFiled($uid, false);
            }
        }
        Log::info('设计师违规记录结束接收到的事件', compact('uid', 'message'));
        $this->setSuccess();
    }
}